#pragma once

#include "Auxiliary.h"


// Forward declaration
class ServerInfo;


/// Represents connection, which opens n sockets and sends data asynchroniously.
class ASyncConnection
{
public:
	ASyncConnection(ServerInfo &Info, size_t SocketCount);

private:
	static void connectHandler(ServerInfo &Info, boost::asio::ip::tcp::socket *s, tbb::tick_count t_start, const boost::system::error_code &error);
		
	static void readHandler(ServerInfo &Info, boost::asio::ip::tcp::socket *s, tbb::tick_count t_start,
							const boost::system::error_code& error, size_t bytes_transferred);

	/// Registers processed request and generates another request.
	static void writeHandler(ServerInfo &Info, boost::asio::ip::tcp::socket *s, tbb::tick_count t_start,
							 const boost::system::error_code &error, size_t bytes_transferred);

private:
	boost::asio::io_service _service;
	static boost::array<unsigned char, 16000> buf;
};
